package valoskmdev.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Vehicle extends EntityBase implements Serializable {

	private static final long serialVersionUID = -5789898937712313032L;

	@Persistent
	private String vin;
	@Persistent
	private String regNumber;
	@Persistent
	@Extension(vendorName = "datanucleus", key = "gae.unindexed", value = "true")
	private String color;
	@Persistent
	private String brand;
	@Persistent
	private String type;
	@Persistent
	private Date prodDate;
	@Persistent(mappedBy = "vehicle")
	@Element(dependent = "true")
	private List<Issue> issues = new ArrayList<Issue>();
	@Persistent
	private AppUser appUser;

	public String getVin() {
		return this.vin;
	}

	public void setVin(final String vin) {
		this.vin = vin;
	}

	public String getRegNumber() {
		return this.regNumber;
	}

	public void setRegNumber(final String regNumber) {
		this.regNumber = regNumber;
	}

	public String getColor() {
		return this.color;
	}

	public void setColor(final String color) {
		this.color = color;
	}

	public String getBrand() {
		return this.brand;
	}

	public void setBrand(final String brand) {
		this.brand = brand;
	}

	public String getType() {
		return this.type;
	}

	public void setType(final String type) {
		this.type = type;
	}

	public Date getProdDate() {
		return this.prodDate;
	}

	public void setProdDate(final Date prodDate) {
		this.prodDate = prodDate;
	}

	public AppUser getAppUser() {
		return this.appUser;
	}

	public void setAppUser(final AppUser appUser) {
		this.appUser = appUser;
	}

	public List<Issue> getIssues() {
		return this.issues;
	}

	public Issue getIssueById(final long id) {
		Issue choosed = null;
		for (final Issue issue : this.getIssues()) {
			if (issue.getId().getId() == id) {
				choosed = issue;
			}
		}
		return choosed;
	}

	@Override
	public String toString() {
		return this.regNumber;
	}

}
